//
//  MPTLiveLoginView.m
//  MPTLive
//
//  Created by caixun on 15/8/21.
//  Copyright (c) 2015年 Jeakin. All rights reserved.
//

#import "MPTLiveLoginView.h"
#import "UIColor+MPTColor.h"
#import "UIFont+MPTFont.h"


@interface MPTLiveLoginView ()

// 登录新浪微博
@property (nonatomic, strong) UIButton *loginBtn;
// 关于秒拍
@property (nonatomic, strong) UIButton *mpAboutBtn;

@end


@implementation MPTLiveLoginView


#pragma mark - ***************************** View Lifecycle ***********************************

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self initMainViews];
    }
    return self;
}

-(void)willMoveToSuperview:(UIView *)newSuperview
{
    [super willMoveToSuperview:newSuperview];
    
    if(newSuperview == nil)
    {
        [[self subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
        
        return ;
    }
}


#pragma mark - ******************************** Init All Views **********************************

- (void)initMainViews
{
    // 半透的遮罩
    UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:self.frame];
    bgImageView.backgroundColor = [UIColor blackColor];
    bgImageView.alpha = 0.5;
    [self addSubview:bgImageView];
    
    // 直播icon
    UIImage *liveIconImg = [UIImage imageNamed:@"MPTLive_LoginIcon"];
    UIImageView *liveIcon = [[UIImageView alloc] initWithFrame:CGRectMake(screenW/2-liveIconImg.size.width/2, 161, liveIconImg.size.width, liveIconImg.size.height)];
    liveIcon.image = liveIconImg;
    [self addSubview:liveIcon];
    
    // app名字图片
    UIImage *yoyo = [UIImage imageNamed:@"miaoPaiZhiBo"];
    UIImageView *yoyoImgv = [[UIImageView alloc] initWithFrame:CGRectMake(liveIcon.frame.origin.x, liveIcon.frame.origin.y+liveIcon.frame.size.height+15, yoyo.size.width, yoyo.size.height)];
    yoyoImgv.image = yoyo;
    [self addSubview:yoyoImgv];
    yoyoImgv.center = CGPointMake(liveIcon.center.x, yoyoImgv.center.y);
    
    // 关于秒拍直播按钮
    CGRect mpAboutRect = CGRectMake(20,
                                    screenH-30-44,
                                    screenW-20*2,
                                    44);
    self.mpAboutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.mpAboutBtn.frame = mpAboutRect;
    [self.mpAboutBtn setTitleColor:[UIColor YXColorWithHexCode:@"#9a9a9a"] forState:UIControlStateNormal];
    [self.mpAboutBtn setTitle:@"秒拍直播是什么" forState:UIControlStateNormal];
    [self.mpAboutBtn setBackgroundColor:[UIColor clearColor]];
    self.mpAboutBtn.layer.cornerRadius = 22;
    self.mpAboutBtn.titleLabel.font = [UIFont YXFontOfSize:16.0f];
    self.mpAboutBtn.clipsToBounds = YES;
    [self addSubview:self.mpAboutBtn];
    
    
    /// 文字下面的线
    UILabel *labLine = [[UILabel alloc] initWithFrame:CGRectMake((screenW - 150) / 2, 30, 108, 0.5)];
    labLine.backgroundColor = [UIColor YXColorWithHexCode:@"#9a9a9a"];
    [self.mpAboutBtn addSubview:labLine];
    
    // 登录按钮
    CGRect loginRect = CGRectMake(self.mpAboutBtn.frame.origin.x,
                                  self.mpAboutBtn.frame.origin.y-10-44,
                                  self.mpAboutBtn.frame.size.width,
                                  self.mpAboutBtn.frame.size.height);
    self.loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.loginBtn.frame = loginRect;
    [self.loginBtn setTitle:@"新浪微博认证账号登录" forState:UIControlStateNormal];
    [self.loginBtn setBackgroundColor:[UIColor YXColorWithHexCode:@"#ffe200"]];
    [self.loginBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.loginBtn.layer.cornerRadius = 22;
    self.loginBtn.titleLabel.font = [UIFont YXFontOfSize:16.0f];
    self.loginBtn.clipsToBounds = YES;
    [self addSubview:self.loginBtn];
}


#pragma mark - ****************************** Functions *********************************

- (void)setTargetForBtn:(id)target
        withLoginAction:(SEL)loginAction
        withAboutAction:(SEL)aboutAction
{
    [self.mpAboutBtn addTarget:target action:aboutAction forControlEvents:UIControlEventTouchUpInside];
    [self.loginBtn addTarget:target action:loginAction forControlEvents:UIControlEventTouchUpInside];
}


@end
